/*
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

package bgtp;

import java.util.*;
import java.lang.*;

public class MessageQueue implements MQInterface
{
    private Vector<TreeMap<String, String>> queue;

    public MessageQueue()
    {
	queue = new Vector<TreeMap<String, String>>();
    }

    public int size()
    {
	return queue.size();
    }
 
    public void add(TreeMap<String, String> ms)
    {
	synchronized(queue)
	    {
		queue.add(ms);
	    }
    }

    public TreeMap<String, String> get()
    {
	synchronized(queue)
	    {
		return queue.remove(0);
	    }
    }

    public Vector<TreeMap<String, String>> getAll()
    {
	Vector<TreeMap<String, String>> tmp;

	if(queue.size() > 0)
	    {
		synchronized(queue)
		    {
			tmp   = queue;
			queue = new Vector<TreeMap<String, String>>();
		    }
		return tmp;
	    }
	return null;
    }
}